﻿using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using Grundy.Common;
using Grundy.Message;

namespace Grundy.CryptographicServices
{
    public abstract class IdentityProvider
    {
        private const string format = "{0}:{1}";
        public abstract IdentifierCollection GetIdentifiers();
        public abstract string Type { get; }

        public override string ToString()
        {
            var identifiers = GetIdentifiers().Select(i => string.Format(format, i.Name, i.Value)).ToList();
            identifiers.Insert(0, string.Format(format, "Type", this.Type));
            var hash = new SHA256Managed().ComputeHash((string.Join(", ", identifiers).ToByteArrayUsingUtf8()));
            return hash.ToHexadecimalString();
        }
    }
}